package com.liyk.shop.controller;

import com.liyk.shop.response.Result;
import com.liyk.shop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: springcloud-demo
 * @description:
 * @author: lyk
 * @create: 2019-11-22 17:05
 **/
@RestController
@RequestMapping(value = "product")
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 列表，触发hystrix熔断机制、执行fallback
     * @return
     */
    @GetMapping(value = "list")
    public Result getList(){
        int i = 1/0;
        return new Result(200,"port:8001",productService.getList());
    }

    /**
     * 获取商品
     * @param id
     * @return
     */
    @GetMapping(value = "get")
    public Result get(@RequestParam("id") String id){
        return Result.success(productService.getById(id));
    }
}
